﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommonDto
{
    public class DefaultBaseResponseBuilder<TData>
    {
        private DefaultBaseResponse<TData> _defaultBaseResponse = null!;

        private DefaultBaseResponseBuilder()
        {
            Init();
        }

        public static DefaultBaseResponseBuilder<TData> GetDefaultBaseResponseBuilder()
        {
            return new DefaultBaseResponseBuilder<TData>();
        }

        public DefaultBaseResponseBuilder<TData> SetCode(string code)
        {
            _defaultBaseResponse.Code = code;
            return this;
        }

        public DefaultBaseResponseBuilder<TData> SetMessage(string message)
        {
            _defaultBaseResponse.Message = message;
            return this;
        }

        public DefaultBaseResponseBuilder<TData> SetSubCode(string subCode)
        {
            _defaultBaseResponse.SubCode = subCode;
            return this;
        }

        public DefaultBaseResponseBuilder<TData> SetSubMessage(string subMessage)
        {
            _defaultBaseResponse.SubMessage = subMessage;
            return this;
        }

        public DefaultBaseResponseBuilder<TData> Reset()
        {
            Init();
            return this;
        }

        private void Init()
        {
            _defaultBaseResponse = new DefaultBaseResponse<TData>
            {
                Code = "0",
                Message = "success",
                SubCode = string.Empty,
                SubMessage = string.Empty,
            };
        }

        public DefaultBaseResponseBuilder<TData> SetData(TData data)
        {
            _defaultBaseResponse.Data = data;
            return this;
        }

        public static implicit operator DefaultBaseResponse<TData>(DefaultBaseResponseBuilder<TData> builder) => builder._defaultBaseResponse;

        public DefaultBaseResponse<TData> Builder() => _defaultBaseResponse;
    }
}
